<!DOCTYPE html>
<html lang='zh-cn'>
<head>
  <meta charset='utf-8' />
  <meta http-equiv='X-UA-Compatible' content='IE=edge' />
  <meta
    name='viewport'
    content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no'
  />
  <meta name='renderer' content='webkit' />
  <title></title>
  <link rel='stylesheet' href='/public/admin/css/pintuer.css' />
  <link rel='stylesheet' href='/public/admin/css/admin.css' />
  <script src='https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.min.js'></script>
  <script src='/public/admin/js/pintuer.js'></script>
</head>
<body>
<div class='panel admin-panel'>
  <div class='panel-head'>
    <strong class='icon-reorder'>博客列表</strong>
    <a href='' style='float: right; display: none'>添加字段</a>
  </div>
  <div class='padding border-bottom'>
    <ul class='search' style='padding-left: 10px'>
      <li>
        <a
          class='button border-main icon-plus-square-o'
          href='/admin/blogs/add'
        >
          添加博客</a
        >
      </li>
      <li>搜索：</li>
      <li>
        <form method='GET'>
          <input
            type='search'
            placeholder='请输入博客名称'
            name='search'
            class='input'
            style='width: 250px; line-height: 17px; display: inline-block'
          />
          <button class='button border-main icon-search'>搜索</button>
          <span style="padding-left: 10px">共有<%= total %>篇博客</span>
        </form>
      </li>
    </ul>
  </div>
  <table class='table table-hover text-center'>
    <tr>
      <th width='100' style='text-align: left; padding-left: 20px'>ID</th>
      <th>博客标题</th>
      <th>博客封面图</th>
      <th>博客分类</th>
      <th>博客作者</th>
      <th>发布时间</th>
      <th>浏览量</th>
      <th width='310'>操作</th>
    </tr>
    <% rows.forEach(item => { %>
    <tr>
      <td>
        <span style='color: red'><%= item.top == 1 ? '置顶' : ''%></span>
        <%= item.id %>
      </td>
      <td><%= item.title %></td>
      <td><img width='200px' src='<%= item.img %>' /></td>
      <td><%= item.tname %></td>
      <td><%= item.author %></td>
      <td><%= item.time %></td>
      <td><%= item.click %></td>
      <td>
        <div class='button-group'>
          <a
            class='button border-main'
            href='/admin/blogs/edit?id=<%= item.id %>'
          ><span class='icon-edit'></span> 修改</a
          >
          <a
            class='button border-red'
            href='javascript:void(0)'
            onclick="return del(this,<%= item.id %>,'<%= item.img %>')"
          ><span class='icon-trash-o'></span> 删除</a
          >
        </div>
      </td>
    </tr>
    <% }) %>
    <tr>
      <td colspan='8'>
        <div class='pagelist'><%- show %></div>
      </td>
    </tr>
  </table>
</div>
</body>
<script>
  function del(obj, id, img) {
    // 确认框
    if (confirm('您确认要删除？')) {
      // 发送ajax请求删除数据
      $.get(
        '/admin/blogs/ajax_delete',
        { id: id, img: img },
        function(data) {
          // 判断是否删除成功
          if (data.success) {
            alert(data.message);
            location.reload();
          } else {
            alert(data.message);
          }
        },
      );
    }
  }
</script>
</html>
